import Vue from 'vue'
import Router from 'vue-router'
import routeDefine from './route-define.js';
import tabRoute from './tab-route.js';
import store from './store'

Vue.use(Router)
Vue.use(tabRoute)

const baseRoutes = [{
  path: '/',
  redirect: '/frame',
},
{
  path: '/frame',
  name: 'frame',
  component: () => import('./frame.vue'),
  },
{
  path: '/login',
  name: 'login',
  component: () => import('./views/login/index.vue'),
}];

const router = new Router({
  routes: baseRoutes.concat(routeDefine),
});

router.beforeEach((to, from, next) => {
  if (to.path === '/frame' && to.query.tab) {
    store.commit('__reshowTab', to.query.tab);
  }
  store.state.spinning = true;
  if (!store.state.isLogin) {
    next(false);
    // Vue.$pub.login();
  } else {
    next();
  }
});

router.afterEach(() => {
  store.state.spinning = false;
});

export default router;